import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { TreeModel } from "/@/api/model/baseModel"

export interface Area extends TreeModel<Area> {
  id?: string // 区域Id(编码)
  areaName?: string // 区域名称
  areaType?: string // 区域类型
}

export const pageArea = (params: Area | any) => {
  return defHttp.get({ url: "/infra-service/area/page", params })
}

export const getArea = (params?: Area | any) => defHttp.get<Area>({ url: "/infra-service/area/get", params })
export const listAreaTreeSelect = (params?: Area | any) => defHttp.get<Area>({ url: "/infra-service/area/listTreeSelect", params })

export const saveOrUpdateArea = (params: Area | any, isUpdate) => {
  const url = isUpdate ? "/infra-service/area/update" : "/infra-service/area/save"
  return defHttp.post({ url: url, params })
}

export const updateAreaStatus = (params: Area | any) => {
  return defHttp.put({ url: "/infra-service/area/updateStatus", params }, { joinParamsToUrl: true })
}

export const deleteArea = (params: Area | any, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除当前区域以及子区域",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/infra-service/area/delete", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
